##  ITEM RESPONSE THEORY: THREE-PARAMETER LOGISTIC MODEL
##  MODEL FOR MEASURMENT OF POLITICAL KNOWLEDGE

model {
	# LOOP OVER N RESPONDENTS
	for (i in 1:N) {        
		# LOOP OVER K ITEMS
	    for (k in 1:K) {    
	    	# LOGISTIC MODEL FOR POLITICAL KNOWLEDGE
	    	y[i,k] ~ dbern (p[i,k])
	    	logit(p.star[i,k]) <- beta[k]*(theta[i] - alpha[k])
	    	p[i,k] <- gamma[k] + (1-gamma[k])*p.star[i,k]
	    }    
	    # DISTRIBUTIONAL ASSUMPTION FOR THE LATENT TRAIT
	    theta[i] ~ dnorm (0, 1)
    }    
             
	# DISTRIBUTIONS OF ITEM PARAMETERS
    for (k in 1:K) {
    	beta[k] ~ dnorm (1, 0.5) T(0,)  # DISCRIMINATION PARAMETER; USUALLY TAKES VALUES BETWEEN 0.5 AND 3
    	alpha[k] ~ dnorm (0, tau.alpha)  # DIFFICULTY PARAMETER
    	
    	gamma.star[k] ~ dunif (0, 1) # GUESSING PARAMETER; BETWEEN 0 AND 1;
    	gamma[k] <- guess.ind[k]*gamma.star[k] # guess.ind[k] INDICATES WHICH ITEMS HAVE A GUESSING PARAMETER
    }   

	tau.alpha ~ dgamma (0.01, 0.01)
	sigma.alpha <- 1/sqrt(tau.alpha)

} # END OF MODEL


